#!/bin/bash
#author 51yuki
#date 2017.10.10
#description install httpd service

SoftDir="/usr/local/src"
InstallDir="/data/application"
#
yum -y install zlib-devel  openssl-devel pcre-devel bzip2 bzip2-devel

#
cd /usr/local/src && \
[ ! -f apr-1.6.3.tar.gz ] && wget http://soft.51yuki.cn/apr-1.6.3.tar.gz
[ ! -f apr-util-1.6.1.tar.gz ] && wget http://soft.51yuki.cn/apr-util-1.6.1.tar.gz
[ ! -f httpd-2.4.27.tar.gz ] && wget http://soft.51yuki.cn/httpd-2.4.27.tar.gz

tar xf apr-1.6.3.tar.gz && cd apr-1.6.3 && ./configure --prefix=/usr/local/apr-1.6.3 && make && make install
cd ..
tar xf apr-util-1.6.1.tar.gz && cd apr-util-1.6.1  && ./configure --prefix=/usr/local/apr-util-1.6.1 --with-apr=/usr/local/apr-1.6.3 && make && make install

cd ..

tar xf httpd-2.4.27.tar.gz && cd httpd-2.4.27
cd httpd-2.4.27

./configure --prefix=${InstallDir}/httpd-2.4.27 --with-apr=/usr/local/apr-1.6.3 --with-apr-util=/usr/local/apr-util-1.6.1 --enable-include --enable-remoteip --with-zlib --with-pcre --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-mpm=worker -enable-modules=all && make && make install 
if [ $? -eq 0 ];then
  ln -sv ${InstallDir}/httpd-2.4.27 ${InstallDir}/httpd
  cp ${InstallDir}/httpd/conf/httpd.conf{,.ori}
fi
vim ${InstallDir}/httpd/conf/httpd.conf <<VIM >/dev/null 2>&1
:96,96s/^$/ServerName localhost:80/
:wq
VIM
cp ${InstallDir}/httpd/conf/mime.types{,.ori}
#apache and php 
cat >> ${InstallDir}/httpd/conf/mime.types <<EOF
application/x-httpd-php             php
application/x-httpd-php-source      phps
EOF
cp ${InstallDir}/httpd-2.4.27/conf/extra/httpd-default.conf{,.original}
sed -i "s/Timeout 60/Timeout 30/" ${InstallDir}/httpd-2.4.27/conf/extra/httpd-default.conf
sed -i "s/ServerTokens Full/ServerTokens Prod/" ${InstallDir}/httpd-2.4.27/conf/extra/httpd-default.conf
sed -i "s/ServerSignature On/ServerSignature Off/" ${InstallDir}/httpd-2.4.27/conf/extra/httpd-default.conf
cat >> /etc/profile.d/httpd.sh <<EOF
export PATH=/data/application/httpd/bin:$PATH
EOF
source /etc/profile.d/httpd.sh
sed "2i#\n# chkconfig: 35 85 35" ${InstallDir}/httpd/bin/apachectl > /etc/init.d/httpd
chmod +x /etc/init.d/httpd
chkconfig --add httpd
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT





